<?php
include_once dirname(__FILE__)."/../../model/config.php";
		$_personne=new personne();
if(isset($_POST["operation"])){
if($_POST["operation"]=="INSERT"){
		if(isset($_POST["NO"])){$_personne->set_NO($_POST["NO"]);}
		if(isset($_POST["Civilite"])){$_personne->set_Civilite($_POST["Civilite"]);}
		if(isset($_POST["Titre"])){$_personne->set_Titre($_POST["Titre"]);}
		if(isset($_POST["Nom"])){$_personne->set_Nom($_POST["Nom"]);}
		if(isset($_POST["Prenom"])){$_personne->set_Prenom($_POST["Prenom"]);}
		if(isset($_POST["CIN"])){$_personne->set_CIN($_POST["CIN"]);}
		if(isset($_POST["login"])){$_personne->set_login($_POST["login"]);}
		if(isset($_POST["MotPasse"])){$_personne->set_MotPasse($_POST["MotPasse"]);}
		if(isset($_POST["Mail"])){$_personne->set_Mail($_POST["Mail"]);}
		if(isset($_POST["AdressePostale"])){$_personne->set_AdressePostale($_POST["AdressePostale"]);}
		if(isset($_POST["NumTelephone"])){$_personne->set_NumTelephone($_POST["NumTelephone"]);}
		if(isset($_POST["NumFax"])){$_personne->set_NumFax($_POST["NumFax"]);}
		if(isset($_POST["NumMobile"])){$_personne->set_NumMobile($_POST["NumMobile"]);}
		if(isset($_POST["CategorieUsager"])){$_personne->set_CategorieUsager($_POST["CategorieUsager"]);}
		if(isset($_POST["CategoriePrincipaleUsager"])){$_personne->set_CategoriePrincipaleUsager($_POST["CategoriePrincipaleUsager"]);}
		if(isset($_POST["IdentifiantInstitutionnel"])){$_personne->set_IdentifiantInstitutionnel($_POST["IdentifiantInstitutionnel"]);}
		if(isset($_POST["OrganismeRattachement"])){$_personne->set_OrganismeRattachement($_POST["OrganismeRattachement"]);}
		if(isset($_POST["LMD"])){$_personne->set_LMD($_POST["LMD"]);}
		if(isset($_POST["Discipline"])){$_personne->set_Discipline($_POST["Discipline"]);}
		$res=$_personne->INSERT(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}
elseif($_POST["operation"]=="DELETE"){
		if(isset($_POST["NO"])){
		$_personne->set_NO($_POST["NO"]);
		$res=$_personne->DELETE(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
		}
}
elseif($_POST["operation"]=="UPDATE"){
		if(isset($_POST["NO"])){$_personne->set_NO($_POST["NO"]);}
		if(isset($_POST["Civilite"])){$_personne->set_Civilite($_POST["Civilite"]);}
		if(isset($_POST["Titre"])){$_personne->set_Titre($_POST["Titre"]);}
		if(isset($_POST["Nom"])){$_personne->set_Nom($_POST["Nom"]);}
		if(isset($_POST["Prenom"])){$_personne->set_Prenom($_POST["Prenom"]);}
		if(isset($_POST["CIN"])){$_personne->set_CIN($_POST["CIN"]);}
		if(isset($_POST["login"])){$_personne->set_login($_POST["login"]);}
		if(isset($_POST["MotPasse"])){$_personne->set_MotPasse($_POST["MotPasse"]);}
		if(isset($_POST["Mail"])){$_personne->set_Mail($_POST["Mail"]);}
		if(isset($_POST["AdressePostale"])){$_personne->set_AdressePostale($_POST["AdressePostale"]);}
		if(isset($_POST["NumTelephone"])){$_personne->set_NumTelephone($_POST["NumTelephone"]);}
		if(isset($_POST["NumFax"])){$_personne->set_NumFax($_POST["NumFax"]);}
		if(isset($_POST["NumMobile"])){$_personne->set_NumMobile($_POST["NumMobile"]);}
		if(isset($_POST["CategorieUsager"])){$_personne->set_CategorieUsager($_POST["CategorieUsager"]);}
		if(isset($_POST["CategoriePrincipaleUsager"])){$_personne->set_CategoriePrincipaleUsager($_POST["CategoriePrincipaleUsager"]);}
		if(isset($_POST["IdentifiantInstitutionnel"])){$_personne->set_IdentifiantInstitutionnel($_POST["IdentifiantInstitutionnel"]);}
		if(isset($_POST["OrganismeRattachement"])){$_personne->set_OrganismeRattachement($_POST["OrganismeRattachement"]);}
		if(isset($_POST["LMD"])){$_personne->set_LMD($_POST["LMD"]);}
		if(isset($_POST["Discipline"])){$_personne->set_Discipline($_POST["Discipline"]);}
		$res=$_personne->UPDATE(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}

}
else{
	$constraint='';$limit=0;$start=0;$pagination='';
	if(isset($_POST["NO"]) && !empty($_POST["NO"])){
		$constraint.=" AND NO='".$_POST["NO"]."'";
	}

	if(isset($_POST["Civilite"]) && !empty($_POST["Civilite"])){
		$constraint.=" AND Civilite='".$_POST["Civilite"]."'";
	}

	if(isset($_POST["Titre"]) && !empty($_POST["Titre"])){
		$constraint.=" AND Titre='".$_POST["Titre"]."'";
	}

	if(isset($_POST["Nom"]) && !empty($_POST["Nom"])){
		$constraint.=" AND Nom='".$_POST["Nom"]."'";
	}

	if(isset($_POST["Prenom"]) && !empty($_POST["Prenom"])){
		$constraint.=" AND Prenom='".$_POST["Prenom"]."'";
	}

	if(isset($_POST["CIN"]) && !empty($_POST["CIN"])){
		$constraint.=" AND CIN='".$_POST["CIN"]."'";
	}

	if(isset($_POST["login"]) && !empty($_POST["login"])){
		$constraint.=" AND login='".$_POST["login"]."'";
	}

	if(isset($_POST["MotPasse"]) && !empty($_POST["MotPasse"])){
		$constraint.=" AND MotPasse='".$_POST["MotPasse"]."'";
	}

	if(isset($_POST["Mail"]) && !empty($_POST["Mail"])){
		$constraint.=" AND Mail='".$_POST["Mail"]."'";
	}

	if(isset($_POST["AdressePostale"]) && !empty($_POST["AdressePostale"])){
		$constraint.=" AND AdressePostale='".$_POST["AdressePostale"]."'";
	}

	if(isset($_POST["NumTelephone"]) && !empty($_POST["NumTelephone"])){
		$constraint.=" AND NumTelephone='".$_POST["NumTelephone"]."'";
	}

	if(isset($_POST["NumFax"]) && !empty($_POST["NumFax"])){
		$constraint.=" AND NumFax='".$_POST["NumFax"]."'";
	}

	if(isset($_POST["NumMobile"]) && !empty($_POST["NumMobile"])){
		$constraint.=" AND NumMobile='".$_POST["NumMobile"]."'";
	}

	if(isset($_POST["CategorieUsager"]) && !empty($_POST["CategorieUsager"])){
		$constraint.=" AND CategorieUsager='".$_POST["CategorieUsager"]."'";
	}

	if(isset($_POST["CategoriePrincipaleUsager"]) && !empty($_POST["CategoriePrincipaleUsager"])){
		$constraint.=" AND CategoriePrincipaleUsager='".$_POST["CategoriePrincipaleUsager"]."'";
	}

	if(isset($_POST["IdentifiantInstitutionnel"]) && !empty($_POST["IdentifiantInstitutionnel"])){
		$constraint.=" AND IdentifiantInstitutionnel='".$_POST["IdentifiantInstitutionnel"]."'";
	}

	if(isset($_POST["OrganismeRattachement"]) && !empty($_POST["OrganismeRattachement"])){
		$constraint.=" AND OrganismeRattachement='".$_POST["OrganismeRattachement"]."'";
	}

	if(isset($_POST["LMD"]) && !empty($_POST["LMD"])){
		$constraint.=" AND LMD='".$_POST["LMD"]."'";
	}

	if(isset($_POST["Discipline"]) && !empty($_POST["Discipline"])){
		$constraint.=" AND Discipline='".$_POST["Discipline"]."'";
	}

	if(isset($_POST['limit'])){$limit=$_POST['limit'];}
	if(isset($_POST['start'])){$start=$_POST['start'];}
	if($limit>0){
		$pagination.=" LIMIT  $start,$limit"; 
}
		$res=$_personne->SELECT($constraint,$pagination); 

		 $data=array();
		  while($row=$_personne->fetch_object()){
		  	$data[]=$row;
	  	  }
  	 	 
		
	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('totalcount' => count($data),'result' => $data ));
	  	
	  }}
?>